home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / CDE / O-Z / Print2Pict3.4.cpt / Print2Pict 3.4ƒ / P2P Extentions ƒ / Print to PICS ƒ / P2PX.h < prev    next >
Text File  |  1992-09-05  |  16KB  |  412 lines

  1. #define _H_P2PX
  2. /*==================================================================================
  3.  
  4. File P2PX.h 
  5. © B.Raoult 1992
  6.  
  7. mab@ecmwf.co.uk
  8.  
  9.  
  10. How to write a Print2Pict extension:
  11. ------------------------------------
  12.  
  13.     A Print2Pict extension is a code resource of type 'P2PX' id = -8192, 
  14. in a file of type 'P2PX' and creator 'P2P '. The code entry point is
  15. a Pascal function (so extension can be wrote in Pascal or C).  
  16.  
  17.     pascal  OSErr main(short msg,P2PXPtr arg);
  18.     
  19.     The function is called with two parameters: the first is a function selector,
  20. the second is a pointer to a parameter block containing various field described
  21. later. The function must return noErr if everything was OK, or the code
  22. of any errors.
  23.     
  24.     When the extension is called, the current resource file is set to the 
  25. extension file. 
  26.  
  27. Values of the message parameter:
  28. ================================                            
  29.      
  30. - getFlagsMsg
  31. -------------
  32.     
  33.     This message is sent before opening the Style or the Job dialogs:
  34.     Print2Pict use the answer to enable or disable some items in the
  35.     dialogs. You must fill the "flags" with the following values:
  36.     
  37.         if  ENVIRONMENT_OK is not set, the name of the extension is disabled in the
  38.         popup menu. It cannot be selected by the user. You must clear this bit
  39.         if your extension requires system features that are not available on this
  40.         machine. (Color QuickDraw, ...)
  41.         
  42.         
  43.         if WANT_FILE_NAMES is set, Print2Pict will generate a filename for every
  44.         page printed and pass it to you in the "fsspec" and "script" fields of
  45.         the argument when sending the putPageMsg message. This name either 
  46.         automatically generated or was specified by the user according to the
  47.         user choice in the Print2Pict options dialog. Use the "creator" field
  48.         to create the files. If you want only one file name, clear the 
  49.         WANT_FILE_NAMES bit once you have received the first putPageMsg message.
  50.         
  51.         if HAS_OWN_PAGE_SIZE is set, Print2Pict will look for a PREC resource
  52.         id = 3 in your resource file to setup the Style dialog. A maximum of
  53.         5 page sizes can be displayed (the sixth is reserved for the custom
  54.         paper size). When this bit is set, the external cannot be selected
  55.         in the Job dialog, as an other size may have been chosen in the Style
  56.         dialog.
  57.         
  58.         if HAS_OWN_OPTIONS is set, your external must provide a DITL resource
  59.         id = -8192, and ICON resource id = -8192 and optionally a cicn resource
  60.         id = -8192. The ICON (or cicn) is displayed in the options dialog.
  61.         If the user click on it, the DITL is then appended to the dialog. Your
  62.         external must respond to the optOpenMsg, optEventMsg, optItemMsg
  63.         and optDoneMsg messages.
  64.         
  65.         if ONLY_BLACK_WHITE is set, Print2Pict will create black and white picture.
  66.         
  67.         if CAN_PREVIEW is set the user can preview the pages before they are
  68.         disposed. If you provide a resource PREV id = -8192 containing a pascal
  69.         string that will be use to change the title of the disposition button in
  70.         the preview dialog.
  71.         
  72.         if CAN_SPOOL is set, Print2Pict may spool the picture to a file if the memory
  73.         is too low. The spooled field is set, spooledfile contains the filespec of
  74.         the spooled picture (PICT format). [NOT YET IMPLEMENTED]
  75.         
  76.     When entering your routine the "flags" field is set with the DEFAULT_FLAGS values
  77.     (ENVIRONMENT_OK + WANT_FILE_NAMES + CAN_PREVIEW).
  78.         
  79.     The getFlagsMsg message is also sent when the application calls PrOpenDoc,
  80.     before sending the initMsg, to check if the ENVIRONMENT_OK is still set.
  81.     
  82.     Don't use any fields of the argument other than the "flags" field.
  83.     
  84.     
  85.         
  86. - initMsg
  87. ---------
  88.  
  89.         The message is sent when the application calls PrOpenDoc. 
  90.         If you need some local storage, allocate a handle, and put it
  91.         in the "data" field of the argument.
  92.             
  93. - endMsg
  94. --------
  95.         The message is sent when the application calls PrCloseDoc.
  96.         You must free any memory allocated, close any opened file.
  97.         
  98.         Always check the "data" field before calling DisposHandle. 
  99.  
  100.  
  101. - putPageMsg
  102. ------------
  103.  
  104.         The message is sent when the application calls PrClosePage.
  105.         This is where you must process the picture.
  106.         
  107.         "error"        is the last error.
  108.         "page"      contains the current page number. (Starting from 1)
  109.         "pict"      contains a handle on the picture of the current page.
  110.         "docName"   is the name of the printed document (can be empty).
  111.         "appName"   is the name of the current application.
  112.         
  113.         If WANT_FILE_NAMES is set in the "flags" field: 
  114.         "fsspec"  is the file spec where the page is to be saved, and
  115.         "script"  the scriptcode to use with FSpCreate.
  116.  
  117.         If CAN_SPOLL is set in the "flags" field, Print2Pict may spool the
  118.         picture to disk if the memory is low. [NOT YET IMPLEMENTED]
  119.         "pict" is the set to NULL, "spooled" is true, and "spoolfile"
  120.         contains the file spec of the file where the picture is spooled
  121.         (PICT format) 
  122.   
  123. - newPageMsg ( added with version 3.4 of Print2Pict )
  124. ------------
  125.  
  126.         The message is sent when the application calls PrOpenPage.
  127.         The current port is the printing port and OpenPicture has been called.
  128.         
  129.         "error"        is the last error.
  130.         "page"      contains the current page number. (Starting from 1)
  131.         "docName"   is the name of the printed document (can be empty).
  132.         "appName"   is the name of the current application.
  133.                   
  134.         
  135. - optOpenMsg
  136. ------------
  137.     
  138.         To receive this message the HAS_OWN_OPTIONS bit must be set.
  139.         Print2Pict display the DITL you provide and calls the external.
  140.         You can allocate some private storage in the "data" field.
  141.         You must initialize the dialog items here.
  142.         "dlog" is the dialog containing your items, "skip" is the number
  143.         of items in this dialog belonging to Print2Pict.
  144.         
  145. - optEventMsg
  146. -------------
  147.  
  148.         To receive this message the HAS_OWN_OPTIONS bit must be set.
  149.         The external is called from the ModalDialog filter procedure.
  150.         
  151.         "dlog" is the dialog containing your items, "skip" is the number
  152.         of items in this dialog belonging to Print2Pict.
  153.         "event" is the events that triggered the call, "itemHit" is the
  154.         item passed to the filter procedure, "retcode" must be set to 
  155.         true if "itemHit" was changed. See InsideMac I page 415 for
  156.         more details about the filter procedure.
  157.  
  158. - optItemMsg
  159. ------------
  160.  
  161.         To receive this message the HAS_OWN_OPTIONS bit must be set.
  162.         The external is called with the item returned by ModalDialog.
  163.         You must update the check boxes and the radio buttons.
  164.         "item" is the value return by ModalDialog.
  165.         "dlog" is the dialog containing your items, "skip" is the number
  166.         of items in this dialog belonging to Print2Pict.
  167.         The dialog item "skip" is a static text you can use to display
  168.         any messages.
  169.  
  170.  
  171. - optDoneMsg
  172. ------------
  173.  
  174.         To receive this message the HAS_OWN_OPTIONS bit must be set.
  175.         Print2Pict calls the external before removing the DITL from the dialog.
  176.         You must get the new values of the dialog items, and release any allocated
  177.         memory.
  178.         "dlog" is the dialog containing your items, "skip" is the number
  179.         of items in this dialog belonging to Print2Pict.
  180.  
  181.  
  182. Values of the P2PXPtr parameter:
  183. ================================     
  184.  
  185.     For every calls, a parameter is passed to the extension. All field are read only
  186. except "flags" and "data".
  187.  
  188.     Print2Pict fills the block with zeros and then sets the fields. So you are sure
  189. that missing fields are set to zero:
  190.  
  191.     ALWAYS CHECK A POINTER (OR HANDLE) FIELD AGAINST NULL BEFORE DEREFERENCING IT.                     
  192.      
  193.     This is a description of the field of the parameter block using the format
  194.     - name (type) [list of messages for which the field is valid]
  195.     
  196. - vers (short) [all]            
  197. --------------------        
  198.  
  199.     Print2Pict version, the low byte contains the major version (3 at present).
  200.     The high byte containt the minor version (4 now). They are swapped for compatibility
  201.     with version 3.0
  202.     
  203. - port (TPPrPort) [putPageMsg,newPageMsg]
  204. -----------------------------------------
  205.  
  206.     Current print graph port.
  207.     
  208. - hPrint (THPrint) [putPageMsg,newPageMsg]
  209. ------------------------------------------
  210.  
  211.     Current print record.
  212.     
  213. - page (short) [putPageMsg,newPageMsg]
  214. --------------------------------------
  215.  
  216.     Current page number (starting from 1).
  217.     
  218. - pict (PicHandle) [putPageMsg]
  219. -------------------------------
  220.  
  221.     Picture of the current page. If NULL, then the picture was spooled (see
  222.     spooled and spoolfile)
  223.     
  224. - color (Boolean) [putPageMsg,newPageMsg]
  225. -----------------------------------------
  226.  
  227.     Set to true if the print grafport is the color port.
  228.     
  229. - flags (long) [all]
  230. --------------------
  231.  
  232.     Set by the extension. See previous paragraph.
  233.  
  234. - error (OSErr) [all]
  235. --------------------
  236.  
  237.     Last error reported by Print2Pict.
  238.  
  239. - data (Handle) [initMsg,putPageMsg,endMsg,newPageMsg]
  240.                 [optOpenMsg,optEventMsg,optItemMsg,optDoneMsg if HAS_OWN_OPTIONS]
  241. ---------------------------------------------------------------------------------
  242.  
  243.     Put here a handle to your private storage. Alocate it when
  244.     you receive initMsg or optOpenMsg, free it when you receive endMsg or optDoneMsg.
  245.  
  246. - docName (Str255) [initMsg,putPageMsg,endMsg,newPageMsg]
  247. ---------------------------------------------------------
  248.  
  249.     Name of the printed document.
  250.     
  251. - appName (Str255) [initMsg,putPageMsg,endMsg,newPageMsg]
  252. ---------------------------------------------------------
  253.  
  254.     Name of the current application.
  255.     
  256. - fspec (FSSpec) [putPageMsg if WANT_FILE_NAMES]
  257. ------------------------------------------------
  258.  
  259.     File spec. where to save the picture to.
  260.     
  261. - script (ScriptCode) [putPageMsg if WANT_FILE_NAMES]
  262. -----------------------------------------------------
  263.  
  264.     script code of fspec (needed for FSpCreate).
  265.     
  266. - creator (OSType) [all]
  267. ------------------------
  268.     
  269.     creator choosen by the user in the Print2Pict options dialog.
  270.  
  271. - spooled (Boolean) [putPageMsg if CAN_SPOLL] [NOT YET IMPLEMENTED]
  272. ------------------------------------------------------------------- 
  273.     
  274.     true if the picture was spooled.
  275.     
  276. - spoolfile (FSSpec) [putPageMsg if CAN_SPOLL] [NOT YET IMPLEMENTED]
  277. --------------------------------------------------------------------    
  278.     
  279.     file spec of the spooled picture (PICT file). set if spooled is true.
  280.     
  281. - dlog  (DialogPtr) [optOpenMsg,optEventMsg,optItemMsg,optDoneMsg if HAS_OWN_OPTIONS]
  282. -------------------------------------------------------------------------------------
  283.  
  284.     Dialog where the your DITL is displayed.
  285.  
  286. - event (EventRecord*) [optEventMsg if HAS_OWN_OPTIONS]
  287. -------------------------------------------------------
  288.  
  289.     Event received in ModalDialog filter procedure.
  290.  
  291. - itemHit (short*) [optEventMsg if HAS_OWN_OPTIONS]
  292. ---------------------------------------------------
  293.  
  294.     Item received in ModalDialog filter procedure.
  295.  
  296. - retcode (Boolean) [optEventMsg if HAS_OWN_OPTIONS]
  297. ----------------------------------------------------
  298.  
  299.     Return code of ModalDialog filter procedure.
  300.  
  301. - skip (short) [optOpenMsg,optEventMsg,optItemMsg,optDoneMsg if HAS_OWN_OPTIONS]
  302. --------------------------------------------------------------------------------
  303.  
  304.     Number of items belonging to Print2Pict in the dialog.
  305.  
  306. - item (short) [optItemMsg if HAS_OWN_OPTIONS]
  307. ----------------------------------------------
  308.     
  309.     Item number returned by ModalDialog.
  310.     
  311. Help:
  312. =====
  313.  
  314.     To provide somme help to the user, add a TEXT resource id = -8192 and
  315.     an optional styl resource, same id. The text will be displayed in the
  316.     Help window.
  317.     
  318. Ideas:
  319. ======    
  320.  
  321.     Here are some ideas of extensions:
  322.     - Print to Movie (QuickTime) each page is a frame.
  323.     - HyperPrint (HyperCard) each page is a card. Has its own paper format (the
  324.       size of a card.
  325.     - Print to RTF, Print to Word, ... all text formats.
  326.     - Print to PCX, GIF, all PC stuff, ....
  327.     - Print to X, XWindows Pixmaps.
  328.     
  329.     You are welcome to send me any extensions you write, so I can add them to 
  330.     the next releases of Print2Pict.
  331.  
  332.  
  333. ==================================================================================*/
  334.  
  335. #include <PrintTraps.h>
  336.  
  337.  
  338. /*============================ Messages =====================================*/
  339.  
  340. /* Get flags */
  341.  
  342. #define getFlagsMsg     1
  343.  
  344.  
  345. /* Printing ... */
  346.  
  347. #define initMsg         2
  348. #define endMsg          3
  349. #define putPageMsg      4
  350. #define newPageMsg      9
  351.  
  352. /* Options */
  353.  
  354. #define optOpenMsg      5
  355. #define optEventMsg     6
  356. #define optItemMsg      7
  357. #define optDoneMsg      8
  358.  
  359. /*=============================== Flags =====================================*/
  360.  
  361.  
  362. #define ENVIRONMENT_OK      1L  /* Set if machine OK (i.e. has color QD,...) */ 
  363. #define WANT_FILE_NAMES     2L  /* If code resource need file names          */
  364. #define HAS_OWN_PAGE_SIZE   4L  /* If the code has its own page size         */
  365. #define CAN_PREVIEW         8L  /* Pages can be previewed before disposed    */
  366. #define HAS_OWN_OPTIONS    16L  /* If code has own options dialog            */
  367. #define ONLY_BLACK_WHITE   32L  /* No color pictures                         */
  368. #define CAN_SPOOL          64L  /* Can use spooled pictures                  */
  369.  
  370. #define DEFAULT_FLAGS       (ENVIRONMENT_OK+WANT_FILE_NAMES+CAN_PREVIEW)
  371.  
  372. /*============================= Parameter block =============================*/
  373.  
  374. typedef struct {
  375.  
  376.     short       vers;       /* Print2Pict major version (3 now)          */
  377.     
  378.     TPPrPort    port;       /* Print graphport                           */
  379.  
  380.     THPrint     hPrint;     /* Print record                              */
  381.     short       page;       /* Current page                              */
  382.     PicHandle   pict;       /* Content of page                           */
  383.     Boolean     color;      /* The printport is a color port             */
  384.     
  385.     long        flags;      /* Code flags                                */
  386.     Handle      data;       /* Free to use                               */
  387.     
  388.     OSErr        error;        /* Last error code                           */
  389.     
  390.     Str255      docName;    /* Name of printed document                  */
  391.     Str255      appName;    /* Name of current application               */
  392.     
  393.     FSSpec      fspec;      /* File spec if WANT_FILE_NAMES              */
  394.     ScriptCode  script;     /* Script code if WANT_FILE_NAMES            */
  395.     OSType      creator;    /* user chosen creator                       */
  396.     
  397.     Boolean     spooled;    /* Picture was spooled                       */
  398.     FSSpec      spoolfile;  /* Spolled picture                           */
  399.     
  400.     /* Stuff for options dialog */
  401.     
  402.     DialogPtr   dlog;       /* The options dialog                        */
  403.     
  404.     EventRecord *event;     /* Event received in ModalDialog filter proc */
  405.     short       *itemHit;   /* Item received in ModalDialog filter proc  */
  406.     Boolean     retcode;    /* Retcode of ModalDialog filter proc        */
  407.     
  408.     short       skip;       /* Number of items belonging to Print2Pict   */
  409.     short       item;       /* Item number returned by modal dialog      */
  410.         
  411. } P2PXRec, *P2PXPtr;
  412.